package com.atguigu.easy;

import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Stack;

public class ValidParentheses20 {
    
    public static void main(String[] args)
    {
          String stack="[]";
          boolean sh =  isValid(stack);
          System.out.println(sh);
    }

    public static boolean isValid(String s) {

        Map<String, String> map = new HashMap<String, String>();
        map.put(")", "(");
        map.put("]", "[");
        map.put("}", "{");
        
        String[] args=s.split("");
        Stack<String> stack=new Stack<String>();
       
        
        for(int i=0;i<args.length;i++)
        {
            if(args[i].equals("]")||args[i].equals(")")||args[i].equals("}"))
            {
               String fold= stack.pop();
               if(!fold.equals(map.get(args[i])))
               {
                  return false;
               }
            } 
            else
            {
            stack.push(args[i]);
            }
           
        }
        if(stack.size()==0)
        {
            return true;
        } else {
            return false;
        }

    }
}